<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Xử lý đăng ký thanh viên</title>
</head>
<body>
	<?php
		include("csdl.php");
		$tendn=$_POST['tendn'];
		$mkhau=$_POST['mkhau'];
		$xnmkhau=$_POST['xnmkhau'];
		$cmnd=$_POST['cmnd'];
		$dienthoai=$_POST['dienthoai'];
		$fax=$_POST['fax'];
		$diachi=$_POST['diachi'];
		$mail=$_POST['mail'];
		$hoten=$_POST['hoten'];
		$knoi=new csdl();
		$laymakh=$knoi->queryCsdl("select max(makh) as max_makh from khachhang");
		$max=mysql_fetch_array($laymakh);
		$max_makh=$max["max_makh"];
		if($max_makh=="")
		{
			
			$makh='0000001';
		}
		else
		{
			$makh='0000123';
			$makh=$makh + 1;
			$c=7-strlen($makh);
			for($i=0;$i<$c;$i++)
			{
				$makh="0".$makh;
			}
			//echo $makh;
		}
		if($knoi->queryCsdl("insert into khachhang values('$makh','$hoten','$cmnd','$diachi','$dienthoai','$fax','$mail')"))
		{
			if($knoi->queryCsdl("insert into taikhoan values('$tendn',md5('$mkhau'),0,'$makh')"))
				echo "Đã đăng ký thành công!";
			else
				echo "Có lỗi xãy ra. Xin vui lòng kiểm tra lại!";
		}
		else
				echo "Có lỗi xãy ra. Xin vui lòng kiểm tra lại!";
	?>
</body>
</html>
